<template>
  <div class="situationexam" v-loading='loading'> 
    <div class='bts-group'>
      <el-button v-for='(item,index) in uploadType'
                  :key='index'
                  @click='goPath(item.path)'
                  :class='activeIndex==index ? "sure":""'>{{item.name}}</el-button>
    </div>         
    <h3 class="table-name">应急预案形式评审表</h3>
    <Table :data='data' ></Table>
    <div class="bts">
      <el-button class='sure' @click='saveData(0)'>保存</el-button>
      <el-button class='sure' @click="saveData(1)">下一步</el-button>
    </div>
</div>
</template>
<script>
import Table from './common/table1'
import config from '../../config.js'
export default {
  components: {
    Table
  },
  data () {
    return {
      data:[],
      name:'',
      varname:'',
      signImg:'',
      loading:false,
      autograph:'',
      activeIndex: 0,
      uploadType: [
        {
          name: '形式评审',
          path: '/tableLay'
        },
        {
          name: '要素评审',
          path: '/tableLay/keyexam2'
        },
        {
          name: '附件要素评审',
          path: '/tableLay/powerexam2'
        },
        {
          name: '个人评审意见',
          path: '/tableLay/personexam2'
        }
      ]
    };
  },
  mounted(){
    this.getData()
    this.signImg = localStorage.signImg
    this.autograph = localStorage.autograph
     this.$nextTick(()=>{
      document.querySelector('.left-box').style.height='903px'
    })
  },
  methods:{
     goPath(path){
      this.saveData(2,path)
    },
     getData(){
       this.loading=true
       this.postData(0,5)
        .then( res=> {
          this.loading=false
            if (res.data.meta.success) {
              this.varname = res.data.data.companyName
              if(res.data.data.list.length>0){
                res.data.data.list.map((item,index)=>{
                  if(item.url){
                      this.signImg = item.url
                  }
                   item.result=item.selectResult
                })
              }
                res.data.data.list.push({
                  reviewContent: [this.signImg],
                  reviewItemOne: "评审专家签字",
                  reviewMethod: "",
                  tableType: "5",
                  flag:0,
                })
                this.data = res.data.data.list
            } else {
               this.$message.warning(res.data.meta.message)
            }
        })
        .catch(function (res) {
           console.log(res)
        })
    },
    saveData(n,path){
      let list=[]
      this.data.map((item,index)=>{
        if(index < (this.data.length-1)){
            list.push({
                  tableId:item.id,
                  result:item.result 
            })
        }
        
      })
      var flag = list.every(item=>{
         return (item.result!='' && item.result)
        })
      if(!flag){
         this.$message.warning('请选择完毕后再保存')
      }else{
     
          this.postData(2,5,list,this.autograph)
          .then(res => {
            if (res.data.meta.success) {
               if(n==1){
                 this.$router.push('/tableLay/keyexam2')
              }else if(n==2){
               this.$router.push(path)
              }else{
                
              this.$message.success(res.data.meta.message)
              }
            } else {
              this.$message.warning(res.data.meta.message)
            }
          })
          .catch(response => {
            console.log(response);
          });
      }
    }
  }
}
</script>
